import 'package:flutter/material.dart';
import 'package:syria_sports/widgets/refresh_win.dart';

import 'my_error_widget.dart';

class ScreenStateWidget extends StatelessWidget {
  final Widget onDone;
  final Widget? onLoading;
  final Widget? onError;
  final bool isLoading;
  final bool isError;

  final bool isDone;
  final bool isEmpty;
  final Function? onRefresh;

  const ScreenStateWidget({
    Key? key,
    required this.onDone,
    required this.isLoading,
    required this.isError,
    required this.isDone,
    this.onLoading,
    this.onError,
    this.isEmpty = false,
    this.onRefresh,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return RefreshWin(
      onRefresh:onRefresh??(){},
      child: Column(
        mainAxisAlignment:(isError || isEmpty)?MainAxisAlignment.center :MainAxisAlignment.start ,
        mainAxisSize: MainAxisSize.max,
        children: [
          if (isLoading)
            (onLoading != null)
                ? onLoading!
                : const SizedBox(
                  height: 4,
                  child: LinearProgressIndicator(
                    minHeight: 4,
                    color: Colors.deepOrange,
                  ),
                )
          else if (isError)
            (onError != null)
                ? onError!
                : MyErrorWidget(
                  onTapped: () => onRefresh?.call(),
                )
          else if (isEmpty)
            const Text(
              'القائمة فارغة!',
              style: TextStyle(
                fontFamily: 'Tajawal',
                fontSize: 18,
                color: Colors.white,
                fontWeight: FontWeight.bold,
              ),
            )
          else
            Expanded(child: RefreshIndicator(onRefresh: () => onRefresh?.call(), child: onDone)),
        ],
      ),
    );
  }
}
